/**
 * Created by Jaye on 2018/2/26.
 */
$(function () {
    initProduct();
});
function initProduct() {
    $.ajax({
        type: "post",
        url: "/product/list/all",
        dataType: "json",
        data: {"data": ""},
        success: function (data) {
            if (data.code == 1000) {
                if (data.data.total > 0) {
                    // var ds=$.parseJSON( data.data);
                    var products = [];
                    products = data.data.records;
                    var div = "";
                    for (var i = 0; i < products.length; i++) {
                        if (i % 3 == 0) {
                            div = div + "<div class='grids_of_3'>";
                        }
                        var product = products[i];
                        div = div + "<div class='grid1_of_3'> <a href='/info?commodityId="+product.commodityId+"'> <img src='images/icon6.png' alt=''/><h3>"+product.commodityName+"</h3>" +
                            "<div class='price'> <h4>¥"+product.price+"<span>查看详情</span></h4></div> <span class='b_btm'></span></a></div>";
                        if ((i + 1) % 3 == 0) {
                            div = div + "<div class='clear'></div></div>";
                        }
                    }
                    $("#productlist").html(div);
                } else {
                    $("#productlist").html("<p align='center'>暂无商品</p>");
                }
            }
        }
    });
}

function addProductgrid() {
    var div = "<div class='grid1_of_3'> <a href='details.html'> <img src='images/pic4.jpg' alt=''/><h3>branded bags</h3>" +
        "<div class='price'> <h4>$300<span>indulge</span></h4></div> <span class='b_btm'></span></a></div>";
}